package com.zdxlz.fcmp.common.mqtt.adapter;

import com.zdxlz.fcmp.common.mqtt.dto.IctMqttRequest;
import com.zdxlz.fcmp.common.mqtt.dto.IctMqttResponse;
import org.eclipse.paho.mqttv5.common.MqttException;
import org.eclipse.paho.mqttv5.common.MqttMessage;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;

/**
 * @author: aman
 * @date 2025/2/10 17:16
 * @description
 */

@Component
public interface ProtocolAdapter {
    /**
     * 初始化协议连接
     */
    void initialize();


    void publichTopic(String topic, IctMqttRequest<?> config);


    CompletableFuture<IctMqttResponse<?>> applyConfigurationAsync(String deviceMac, IctMqttRequest<?> config);

    /**
     * 订阅设备状态变更
     *
     */
    void subscribeState(String topic, BiConsumer<String, MqttMessage> handler) throws MqttException;

    /**
     * 协议健康检查
     *
     * @return 是否处于可用状态
     */
    boolean isHealthy();

    /**
     * 断开协议连接
     */
    void disconnect();

    /**
     * 获取协议类型标识
     */
    String getProtocolType();

    // 状态监听器接口
    @FunctionalInterface
    interface StateChangeListener {
        void onStateChanged(String deviceId, Map<String, Object> state);
    }
}
